package com.chencong.transform;

import com.chencong.bean.UserOrderCount;
import com.chencong.env.FlinkTableEnv;
import com.chencong.udf.SourceFromMysqlFunc;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author chencong
 * @Description map操作
 * @Date 7:50 下午 2021/8/17
 * @Param
 **/
public class Map {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment streamTableEnvironment = FlinkTableEnv.getStreamTableEnvironment();
        streamTableEnvironment.setParallelism(1);

        DataStreamSource<UserOrderCount> userOrderCountDataStreamSource = streamTableEnvironment.addSource(new SourceFromMysqlFunc());

        SingleOutputStreamOperator<String> mapResult = userOrderCountDataStreamSource.map(new MapFunction<UserOrderCount, String>() {
            @Override
            public String map(UserOrderCount value) throws Exception {
                return value.userId;
            }
        });

        mapResult.print();

        streamTableEnvironment.execute();
    }
}
